﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Runtime.CompilerServices;


using ConstructionBidOnline.DAL;
using ConstructionBidOnline.DAL.dsMembershipSettingsTableAdapters;
using ConstructionBidOnline.Common;

namespace ConstructionBidOnline.Biz
{
   public class ConsultantSettings:BOBase
    {
       #region Construction / Disposal

        /// <summary>
        /// Default constructor.
        /// </summary>
       protected ConsultantSettings() { }

        #endregion

       #region Public Properties

       #region Instance Properties

       /// <summary>
       /// PKID of the ConsultantSettings.
       /// </summary>
       public int ConsultantSettingsID
       {
           get { return _consultantsettingsID; }
           set
           {
               if (_consultantsettingsID != value)
               {
                   if (OnPropertyChanging("ConsultantSettingsID", _consultantsettingsID, value))
                   {
                       int oldValue = _consultantsettingsID;
                       _consultantsettingsID = value;

                       OnPropertyChanged("ConsultantSettingsID", oldValue, value);
                   }
               }
           }
       }  private int _consultantsettingsID = -1;

       /// <summary>
       /// Contractor Type Value.
       /// </summary>
       public string MembershipType
       {
           get { return _membershiptype; }
           set
           {
               if (_membershiptype != value)
               {
                   if (OnPropertyChanging("MembershipType", _membershiptype, value))
                   {
                       string oldValue = _membershiptype;
                       _membershiptype = value;
                       OnPropertyChanged("MembershipType", oldValue, value);
                   }
               }
           }
       }  private string _membershiptype = null;


       /// <summary>
       /// Transaction Fees Value.
       /// </summary>
       public decimal TransactionFees
       {
           get { return _transactionfees; }
           set
           {
               if (_transactionfees != value)
               {
                   if (OnPropertyChanging("TransactionFees", _transactionfees, value))
                   {
                       decimal oldValue = _transactionfees;
                       _transactionfees = value;
                       OnPropertyChanged("TransactionFees", oldValue, value);
                   }
               }
           }
       }  private decimal _transactionfees = 0;


       /// <summary>
       /// Membership Fees Value.
       /// </summary>
       /// 

       public decimal MembershipFees
       {
           get { return _membershipfees; }
           set
           {
               if (_membershipfees != value)
               {
                   if (OnPropertyChanging("MembershipFees", _membershipfees, value))
                   {
                       decimal oldValue = _membershipfees;
                       _membershipfees = value;
                       OnPropertyChanged("MembershipFees", oldValue, value);
                   }
               }
           }
       }  private decimal _membershipfees = 0;







       /// <summary>
       /// Contract Fees  Value.
       /// </summary>
       /// 

       public decimal ContractFees
       {
           get { return _contractfees; }
           set
           {
               if (_contractfees != value)
               {
                   if (OnPropertyChanging("ContractFees", _contractfees, value))
                   {
                       decimal oldValue = _contractfees;
                       _contractfees = value;
                       OnPropertyChanged("ContractFees", oldValue, value);
                   }
               }
           }
       }  private decimal _contractfees = 0;





       /// <summary>
       /// NumberOfKeywords.
       /// </summary>
       public int NumberOfKeywords
       {
           get { return _numberOfKeywords; }
           set
           {
               if (_numberOfKeywords != value)
               {
                   if (OnPropertyChanging("NumberOfKeywords", _numberOfKeywords, value))
                   {
                       int oldValue = _numberOfKeywords;
                       _numberOfKeywords = value;

                       OnPropertyChanged("NumberOfKeywords", oldValue, value);
                   }
               }
           }
       }  private int _numberOfKeywords = -1;





       /// <summary>
       /// Virtual Assistant.
       /// </summary>
       /// 

       public string VirtualAssistant
       {
           get { return _virtualassistant; }
           set
           {
               if (_virtualassistant != value)
               {
                   if (OnPropertyChanging("VirtualAssistant", _virtualassistant, value))
                   {
                       string oldValue = _virtualassistant;
                       _virtualassistant = value;
                       OnPropertyChanged("VirtualAssistant", oldValue, value);
                   }
               }
           }
       }  private string _virtualassistant = null;




       /// <summary>
       /// Video Protfolio Value.
       /// </summary>
       /// 

       public string VideoProtfolio
       {
           get { return _videoprotfolio; }
           set
           {
               if (_videoprotfolio != value)
               {
                   if (OnPropertyChanging("VideoProtfolio", _videoprotfolio, value))
                   {
                       string oldValue = _videoprotfolio;
                       _videoprotfolio = value;
                       OnPropertyChanged("VideoProtfolio", oldValue, value);
                   }
               }
           }
       }  private string _videoprotfolio = null;


       /// <summary>
       /// Photo Gallery Value.
       /// </summary>
       /// 

       public string PhotoGallery
       {
           get { return _photogallery; }
           set
           {
               if (_photogallery != value)
               {
                   if (OnPropertyChanging("PhotoGallery", _photogallery, value))
                   {
                       string oldValue = _photogallery;
                       _photogallery = value;
                       OnPropertyChanged("PhotoGallery", oldValue, value);
                   }
               }
           }
       }  private string _photogallery = null;


       #endregion

       #endregion

       #region Public Methods

       #region CreateNew

       /// <summary>
       /// Creates a new, empty ConsultantSettings object.
       /// </summary>
       public static ConsultantSettings CreateNew()
       {
           ConsultantSettings obj = new ConsultantSettings();

           // Switch state to Added prior to initializing property values.
           obj.ObjState = ObjectState.Added;

           //obj.ValidUpTo = DateTime.Now;

           return (obj);
       }


       [MethodImpl(MethodImplOptions.Synchronized)]
       public static ConsultantSettings CreateNew(ConsultantSettingsCollection collection)
       {
           ConsultantSettings obj = CreateNew();

           // Get next/unique ID for the new object.
           int minVal = 0;
           foreach (ConsultantSettings consultantsettings in collection)
           {
               if (consultantsettings.ConsultantSettingsID < minVal)
                   minVal = consultantsettings.ConsultantSettingsID;
           }
           obj.ConsultantSettingsID = --minVal;
           collection.Add(obj);

           return (obj);
       }

       #endregion

       #region GetAllConsultantSettings

       /// <summary>
       /// Returns a collection of all ConsultantSettings.
       /// </summary>
       public static ConsultantSettingsCollection GetAllConsultantSettings()
       {
           Consultant_SettingsTableAdapter adapter = new Consultant_SettingsTableAdapter();
           adapter.Connection = AppSettings.GetDbConn();

           dsMembershipSettings.Consultant_SettingsDataTable tbl = adapter.GetData(null);

           ConsultantSettingsCollection list = new ConsultantSettingsCollection();

           if (tbl.Rows.Count > 0)
           {
               foreach (dsMembershipSettings.Consultant_SettingsRow row in tbl.Rows)
               {
                   ConsultantSettings consultantsettings = new ConsultantSettings();
                   RelationalToObject(consultantsettings, row);
                   list.Add(consultantsettings);
               }
           }

           return (list);
       }

       #endregion

       #region GetConsultantSettingsByID

       /// <summary>
       /// Returns an ConsultantSettings object for the specified 'ConsultantSettingsID' or null if no ConsultantSettings with the specified parameter(s) exists.
       /// </summary>
       public static ConsultantSettings GetContractorSettingsByID(int consultantsettingsID)
       {
           Consultant_SettingsTableAdapter adapter = new Consultant_SettingsTableAdapter();
           adapter.Connection = AppSettings.GetDbConn();
           dsMembershipSettings.Consultant_SettingsDataTable tbl = adapter.GetData(consultantsettingsID);

           if (tbl.Rows.Count == 1)
           {
               ConsultantSettings ms = new ConsultantSettings();
               RelationalToObject(ms, tbl.Rows[0]);
               return (ms);
           }
           else if (tbl.Rows.Count > 1)
               throw new ApplicationException("Database integrity error: Specified 'Settings' returned more than one User record.");

           return (null);
       }

       #endregion

       #region GetConsultantSettingsByMembershipType

       /// <summary>
       /// Returns an ConsultantSettings object for the specified 'MembershipType' or null if no ConsultantSettings with the specified parameter(s) exists.
       /// </summary>
       public static ConsultantSettings GetConsultantSettingsByMembershipType(string membershiptype)
       {
           Consultant_SettingsTableAdapter adapter = new Consultant_SettingsTableAdapter();
           adapter.Connection = AppSettings.GetDbConn();
           dsMembershipSettings.Consultant_SettingsDataTable tbl = adapter.GetDataByMembershipTypeConsultant(membershiptype);

           //MembershipSettingsCollection list=new MembershipSettingsCollection();

           if (tbl.Rows.Count == 1)
           {
               ConsultantSettings ms = new ConsultantSettings();
               RelationalToObject(ms, tbl.Rows[0]);
               return (ms);

           }
           else if (tbl.Rows.Count > 1)
               throw new ApplicationException("Database integrity error: Specified 'MembershipType' returned more than one MembershipSettings.");

           return (null);
       }

       #endregion

       #region Update

       /// <summary>
       /// Updates the specified ContractorSettings.
       /// </summary>
       public static void Update(ConsultantSettings obj)
       {
           bool updateconsultantsettings = false;

           // Do not update invalid objects.
           if (!obj.Validate())
           {
               StringBuilder sb = new StringBuilder(2048);
               sb.Append("The object being updated has one or more invalid properties; the Update() operation for this object has been cancelled.\nError(s):");
               foreach (ValidationError err in obj.Errors)
                   sb.Append("\n* " + err.Element + ": " + err.Message);

               throw new InvalidObjectException(sb.ToString());
           }
           else
           {
               updateconsultantsettings = (obj.ObjState != ObjectState.Unchanged);

               if (!updateconsultantsettings)
                   return;
           }

           ObjectState originalObjectState = obj.ObjState;

           dsMembershipSettings.Consultant_SettingsDataTable tbl = null;
           if (updateconsultantsettings)
           {

               Consultant_SettingsTableAdapter adapter = new Consultant_SettingsTableAdapter();
               adapter.Connection = AppSettings.GetDbConn();


               tbl = new dsMembershipSettings.Consultant_SettingsDataTable();
               dsMembershipSettings.Consultant_SettingsRow row = tbl.NewConsultant_SettingsRow();
               ObjectToRelational(obj, tbl, row);

               adapter.Update(tbl);

               if (originalObjectState == ObjectState.Deleted)
                   obj = null;
               else RelationalToObject(obj, tbl.Rows[0]);
           }
       }

       #endregion

       #region Validate

       /// <summary>
       /// Validates the object based on its properties at the time of the call; updates the Errors property.
       /// </summary>
       public override bool Validate()
       {
           Errors.Clear();

           if (ObjState == ObjectState.Unchanged)
           {
               // By definition, unchanged objects are valid.
               return (true);
           }
           else if (ObjState == ObjectState.Uninitialized)
           {
               Errors.Add(new ValidationError("object", "Object is uninitialized.", ValidationError.Severity.Error));

               // No need to proceed past this error.
               return (false);
           }
           else if ((ObjState == ObjectState.Deleted) && (ConsultantSettingsID <= 0))
           {
               // Deleted items must have 'real' (i.e. non-negative, non-zero) key(s) to be valid.
               Errors.Add(new ValidationError("ConsultantSettingsID", "Deleted object has an invalid PKID.", ValidationError.Severity.Error));

               // No need to proceed past this error.
               return (false);
           }
           else  // ObjState == Added | Modified
           {

               // BusinessName is required.
               if ((MembershipType == null) || (MembershipType.Trim().Length == 0))
               {
                   Errors.Add(new ValidationError("MembershipType", "MembershipType is required.", ValidationError.Severity.Error));
               }
               else if (ObjState == ObjectState.Added)
               {

               }

           }

           return (Errors.Count == 0);
       }

       #endregion

       #region ToString

       /// <summary>
       /// User-friendly string represetation of this object.
       /// </summary>
       public override string ToString()
       {
           return (String.Format("ConsultantSettings: MSID={0}, MembershipType={1}, {2}", ConsultantSettingsID, MembershipType));
       }

       #endregion


       #endregion
    }





   /// <summary>
   /// Collection of 0 or more SubAdmin objects.
   /// </summary>

   public class ConsultantSettingsCollection : List<ConsultantSettings>
   {

       #region Types

       public class UserComparer : IComparer<ConsultantSettings>
       {
           public int Compare(ConsultantSettings user1, ConsultantSettings user2)
           {
               return (String.Compare(user1.MembershipType, user2.MembershipType));
           }
       }

       #endregion

       #region Public Methods

       #region FindByConsultantSettingsID

       public ConsultantSettings FindByConsultantSettingsID(int consultantsettingsID)
       {
           for (int ndx = 0; ndx < this.Count; ndx++)
               if (this[ndx].ConsultantSettingsID == consultantsettingsID)
                   return (this[ndx]);

           return (null);
       }

       #endregion

       #region FindByMembershipType

       /// <summary>
       /// Case insensitve compare.
       /// </summary>
       public ConsultantSettings FindByMembershipType(string membershiptype)
       {
           for (int ndx = 0; ndx < this.Count; ndx++)
               if (this[ndx].MembershipType == membershiptype)
                   return (this[ndx]);

           return (null);
       }

       #endregion

       #endregion

   }
}
